package com.huiyujinrong.qiangdanbao.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.huiyujinrong.qiangdanbao.R;
import com.huiyujinrong.qiangdanbao.bean.RecordBean;
import com.huiyujinrong.qiangdanbao.utils.DataUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


public class RecordAdapter extends BaseAdapter {

    private List<RecordBean.list> list;
    private Context context;

    public RecordAdapter(List<RecordBean.list> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_record, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if (list.get(position).getTrade_purpose().contains("抢单成功")) {
            holder.purpouse.setText("抢单成功");
            holder.icon.setBackgroundResource(R.drawable.icon_deal_success2);
        } else if (list.get(position).getTrade_purpose().contains("认证成功")) {
            holder.purpouse.setText("认证成功");
            holder.icon.setBackgroundResource(R.drawable.icon_deal_renzheng);
        } else if (list.get(position).getTrade_purpose().contains("新人注册")) {
            holder.purpouse.setText("新人注册");
            holder.icon.setBackgroundResource(R.drawable.icon_deal_new);
        } else {
            holder.purpouse.setText("充值成功");
            holder.icon.setBackgroundResource(R.drawable.icon_deal_success1);
        }

        holder.time.setText(DataUtils.getDate(list.get(position).getCreate_time()));

        holder.amt.setText(list.get(position).getTrade_amt() + "借币");

        return convertView;
    }

    class ViewHolder {
        @BindView(R.id.itm_rc_icon)
        ImageView icon;
        @BindView(R.id.itm_rc_purpouse)
        TextView purpouse;
        @BindView(R.id.itm_rc_time)
        TextView time;
        @BindView(R.id.itm_rc_amt)
        TextView amt;

        public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
